<template>
	<div>
		<div class="h2">班主任问卷</div>
		<div id="components-form-demo-advanced-search">
			<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
				<a-row :gutter="24">
					<!-- <a-col :span="8">
						<a-form-item label="关键字">
							<a-input autocomplete="off" class="field-right" placeholder="请输入关键字搜索"
								v-decorator="[`key`]" />
						</a-form-item>
					</a-col> -->
					<a-col :span="8">
						<a-form-item label="月份">
							<!-- <a-date-picker  @change="ChangeData" v-decorator="['data']"  format="YYYY-MM"/> -->
							<a-month-picker placeholder="选择月份" v-decorator="['data']" format="YYYY-MM"
								valueFormat="YYYY-MM" @change="onChange($event, 'time')" />
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="问卷" style="display: flex;align-items: center;" class="lableBox">
							<a-select :allowClear="true" v-decorator="['headMasterEvaluationID']" placeholder="全部"
								optionFilterProp="children" showSearch>
								<a-select-option v-for="(item, index) in EvaluationData" :key="index" :value="item.ID">
									{{ item.Name }}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<a-col :span="8">
						<a-form-item label="班级" style="display: flex;align-items: center;" class="lableBox">
							<a-select :allowClear="true" v-decorator="['classID']" placeholder="全部"
								optionFilterProp="children" showSearch>
								<a-select-option v-for="(item, index) in ClassData" :key="index" :value="item.ID">
									{{ item.Name }}/{{item.DepaerName}}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<!--
					<a-col :span="8">
						<a-form-item label="学期">
							<a-select :allowClear="true" v-decorator="['semesterID']" placeholder="全部"
								optionFilterProp="children" showSearch>
								<a-select-option v-for="(item, index) in SemesterList" :key="index" :value="item.ID">
									{{ item.Name }}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col> -->
					

				</a-row>
			</a-form>
		</div>
		<a-button-group size="default" class="option">
			<a-button type="primary" @click="handleSearch">搜索</a-button>
			<a-button @click="handleReset">重置</a-button>
		</a-button-group>
		<div>
			<!-- <el-table stripe ref="singleTable" :data="data" v-loading="loading" highlight-current-row
				style="width: 100%;">
				<el-table-column type="index" label="序号" width="60" fixed="left"></el-table-column>
				<el-table-column prop="AverageScore" label="平均分" show-overflow-tooltip></el-table-column>
			</el-table> -->
			<!-- 评语 -->
			<!-- <el-table :data="dataTwo">
				<el-table-column type="index" label="序号" width="60" fixed="left"></el-table-column>
				<el-table-column prop="Content" label="评语" show-overflow-tooltip></el-table-column>
			</el-table>

			 -->
			<div class="cardbox">
				<div class="pingjun">
				
				<span v-if="data.length>0">平均分：{{data[0].AverageScore||'0'}}分</span>
				<span v-else>平均分：0分</span>
				</div>
				<div class="tips">评语列表：</div>
				<a-list item-layout="horizontal" :data-source="dataTwo">
					<a-list-item slot="renderItem" slot-scope="item">
						<a-row style="width: 100%;border-bottom: 1rpx dashed #eee;">
							<p>{{item.Content}}</p>
							<p style="text-align: right;">{{item.AddTime}}</p>
						</a-row>
					</a-list-item>
				</a-list>
				<el-pagination @size-change="handleSizeChange1" @current-change="handleCurrentChange1"
					:current-page="pagination1.currentPage" :page-sizes="pagination1.pageSizeOptions"
					:page-size="pagination1.pageSize" layout="total, sizes, prev, pager, next, jumper"
					:total="pagination1.total"></el-pagination>
			</div>

		</div>
		<!-- <add :text="text" :DepartCodeList="DepartCodeList" :ClassList="ClassList" v-show="addIf" @closeFun="closeFun">
		</add> -->
	</div>
</template>

<script>
	import Cache from '@/utils/cache';
	// import add from './add';
	import Func from '@/utils/func';
	import moment from 'moment';
	import {
		UserHeadMasterEvaluationTeacherDoGetScorePageList,
		ManageHeadMasterEvaluationDoDelete,
		GetDepartList,
		GetClassList,
		DoUnbundTeacher,
		DoEnableTeacher,
		DoGetSemesterListCommon,
		UserCreditApplyTeacherDoGetClassList,
		CommonDoGetHeadMasterEvaluationList,
		UserHeadMasterEvaluationTeacherDoGetPageList
	} from '@/api/follow';
	const data = [];
	export default {
		components: {
			// add
		},
		data() {
			return {
				dataARR: [{
					Content: 'Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1Ant Design Title 1',
					AddTime:'2011-20-10'
				}],
				EvaluationData: [],
				ClassData: [],
				SemesterList: [],
				data,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination1: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				addIf: false,
				text: {},
				visible: false,
				confirmLoading: false,
				itemId: '',
				gradeYear: null,
				yearPickShow: false,
				departmentList: [],
				worklist: [],
				loading: false,
				values: {},
				dataTwo: [],
				pages: {
					pageIndex: 1,
					pageSize: 20
				},
				tableHeight: parseFloat(window.innerHeight - 160),
				ClassList: [],
				DepartCodeList: [],
				requestUrl: this.global.requestUrl,
				token: Cache.get('token'),
				yearPickShow: false
			};
		},
		computed: {},
		created() {
			this.getNowTime();
			this.getOtherList();
			
		},
		mounted() {},
		methods: {
			getNowTime() {
				var now = new Date();
				var year = now.getFullYear(); //得到年份
				var month = now.getMonth(); //得到月份
				var day = now.getDate(); //得到天
				if (day < 10) {
					day = "0" + day
				}
				month = month + 1;
				month = month.toString().padStart(2, "0");
				console.log(year + '-' + month);
				let that = this;
				that.$nextTick(() => {
					setTimeout(function() {
						that.form.setFieldsValue({
							data: year + '-' + month,
						});
					}, 300);
				})
				this.values.startTime = year + '-' + month + '-01';
				this.values.endTime = year + '-' + month + '-01'
				// /**
				//  * 获取月初到月末，年初到年末
				//  * **/
				// this.today.date_from = `${year}-${month}-${day}`
				// this.today.date_to = `${year}-${month}-${day}`
				// this.month.date_from = `${year}-${month}-01`
				// this.month.date_to = `${year}-${month}-31`
				// this.year.date_from = `${year}-01-01`
				// this.year.date_to = `${year}-12-31`
			},
			moment,
			ChangeData(value) {
				console.log(value);
				console.log(moment(value).format('YYYY-MM'));
				this.values.startTime = moment(value).format('YYYY-MM');
				this.values.endTime = moment(value).format('YYYY-MM');
			},
			exportList() {
				this.form.validateFields((error, values) => {
					let data = {};
					data.key = values.key;
					data.departCode = values.departCode;
					let hrefUrl = this.requestUrl + 'Manage/Teacher/DoExport?userToken=' + encodeURIComponent(this
						.token);
					let hrefStr = '';
					for (let key in data) {
						if (data[key]) {
							hrefStr += key + '=' + data[key] + '&';
						}
					}
					window.open(hrefUrl + '&' + hrefStr, '_blank');
				});
			},

			// hangClick(e) {
			// 	console.log(e);
			// 	this.getNextList(e.HeadMaster)
			// },
			async getNextList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				// data.headMasterEvaluationID=HeadMaster;
				data.pageIndex = this.pagination1.currentPage;
				data.pageSize = this.pagination1.pageSize;
				let res = await UserHeadMasterEvaluationTeacherDoGetPageList(data);
				this.loading = false;
				this.dataTwo = res.data.data;
				const pagination = {
					...this.pagination1
				};
				pagination.total = res.data.pageInfo.TotalItemCount;
				this.pagination1 = pagination;
			},
			onChange(values) {
				this.values.startTime = values + '-01'
				this.values.endTime = values + '-01'
			},
			handleSearch(e) {
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					values.startTime = values.data + '-01'
					values.endTime = values.data + '-01'
				
					this.values = values;
					this.getList();
					this.getNextList();
				});
			},
			handleReset() {
				this.form.resetFields();
				this.values = {};
				this.gradeYear = null;
				this.getList();
			},
			handleSizeChange1(val) {
				this.pagination1.pageSize = val;
				this.getNextList();
			},
			handleCurrentChange1(val) {
				this.pagination1.currentPage = val;
				this.getNextList();
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.pageIndex = this.pagination.currentPage;
				data.pageSize = this.pagination.pageSize;
				let res = await UserHeadMasterEvaluationTeacherDoGetScorePageList(data);
				this.loading = false;
				this.data = res.data.data;
				const pagination = {
					...this.pagination
				};
				pagination.total = res.data.pageInfo.TotalItemCount;
				this.pagination = pagination;
			},
			async getOtherList() {
				let res = await DoGetSemesterListCommon();
				this.SemesterList = res.data.data;
				let res1 = await UserCreditApplyTeacherDoGetClassList();
				this.ClassData = res1.data.data;
				let res2 = await CommonDoGetHeadMasterEvaluationList();
				this.EvaluationData = res2.data.data;
				let that = this;
				that.$nextTick(() => {
					setTimeout(function() {
						that.form.setFieldsValue({
							headMasterEvaluationID: res2.data.data[0].ID || '',
						});

					}, 300);
				})
				this.values.headMasterEvaluationID = res2.data.data[0].ID || '0'
				that.getList();
				that.getNextList();


			},
			addList() {
				this.text = {};
				this.addIf = !this.addIf;
			},
			modifyList(text) {
				text = Object.assign(text, {
					time: new Date()
				});
				this.addIf = !this.addIf;
				this.text = text;
			},
			deleteList(text, type) {
				let that = this;
				this.$confirm({
					title: '提示',
					content: type == 1 ? `您确定删除该问卷吗？` : type == 2 ? `您确定要解绑该教师的微信吗？` : `您确定要修改该老师的状态吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.id = text.ID;
						let res = type == 1 ? await ManageHeadMasterEvaluationDoDelete(data) : type == 2 ?
							await DoUnbundTeacher(data) : await DoEnableTeacher(data);
						if (res.data.code == 0) {
							that.getList();
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			seeList(text, name) {
				this.$router.push({
					name: name,
					query: {
						ID: text.ID,
						Name: text.Name,
					}
				});
			},
			closeFun() {
				this.addIf = false;
				this.getList();
			}
		}
	};
</script>

<style lang="less" scoped>
	/deep/.el-pagination{
		float: none !important;
	}
	/deep/.ant-form-item {
		display: flex;
		margin-bottom: 10px !important;
	}

	/deep/.ant-form-item-label {
		width: 80px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		text-align: right;
	}

	/deep/.ant-form-item-control-wrapper {
		flex: 1;
	}

	/deep/.ant-calendar-picker {
		width: 100%;
	}
	.cardbox{
		width: 90%;
		margin: 0 auto;
		box-shadow: 0px 3px 6px rgba(0,0,0,0.3);
		    border-radius: 16px;
		    padding: 30px 20px;
			box-sizing: border-box;
	}
	.pingjun{
		font-size: 24px;
		color: #5083ee;
		text-align: center;
	}
	.tips{
		font-size: 14px;
		color: #000;
		font-weight: bold;
	}
</style>
